home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / pyshared / checkbox / requires.py < prev    next >
Encoding:
Python Source  |  2009-04-27  |  1.8 KB  |  67 lines

  1. #
  2. # This file is part of Checkbox.
  3. #
  4. # Copyright 2008 Canonical Ltd.
  5. #
  6. # Checkbox is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # Checkbox is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with Checkbox.  If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. from checkbox.lib.cache import cache
  20.  
  21. from checkbox.registry import registry_eval_recursive
  22.  
  23.  
  24. class Requires(object):
  25.  
  26.     def __init__(self, registry, source):
  27.         self._registry = registry
  28.         self._source = source
  29.         self._mask = [False]
  30.  
  31.     def __str__(self):
  32.         return self.get_source() or ""
  33.  
  34.     @cache
  35.     def get_values(self):
  36.         if self._source is None:
  37.             self._mask = [True]
  38.             return []
  39.  
  40.         return registry_eval_recursive(self._registry,
  41.             self._source, self._mask)
  42.  
  43.     def get_packages(self):
  44.         packages = []
  45.         values = self.get_values()
  46.         for value in values:
  47.             if value.__class__.__name__ == "PackageRegistry":
  48.                 packages.append(value)
  49.  
  50.         return packages
  51.  
  52.     def get_devices(self):
  53.         devices = []
  54.         values = self.get_values()
  55.         for value in values:
  56.             if value.__class__.__name__ == "DeviceRegistry":
  57.                 devices.append(value)
  58.  
  59.         return devices
  60.  
  61.     def get_source(self):
  62.         return self._source
  63.  
  64.     def get_mask(self):
  65.         self.get_values()
  66.         return self._mask
  67.